package com.mmall.controller.backend;


import com.mmall.common.ServerResponse;
import com.mmall.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manage/user/")
@Slf4j
public class ManageUserController {

    @Autowired
    private IUserService iUserService;


    @RequestMapping(value = "login.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse login(String username, String password) {
        return iUserService.manageLogin(username, password);
    }

    @RequestMapping(value = "list.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse list(HttpSession session,
                               @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        ServerResponse serverResponse = iUserService.checkAdminRole(session);
        if(!serverResponse.is_success()){
            return serverResponse;
        }
        return iUserService.list(pageNum,pageSize);
    }

}
